package com.lz.seata.domain;

import lombok.Data;

/**
 * @Description: ResultVO 自定义返回对象
 * @Date: 2020/5/4 11:34
 * @Author: LiZhen
 * @Version: 1.0
 */
@Data
public class ResultVO<T> {
    private Integer code;
    private T data;
    private String message;

    private ResultVO(T data) {
        this.code = 0;
        this.data = data;
        this.message = message;
    }

    private ResultVO(CodeMsg codeMsg) {
        this.message = codeMsg.getMsg();
        this.code = codeMsg.getCode();
    }

    public static <T> ResultVO<T> success(T data) {
        return new ResultVO<>(data);
    }

    public static <T> ResultVO<T> success(CodeMsg codeMsg) {
        return new ResultVO<>(codeMsg);
    }

    public static <T> ResultVO<T> error(CodeMsg codeMsg) {
        if (codeMsg == null) {
//            log.warn("codeMsg is null");
            return null;
        }
        return new ResultVO<T>(codeMsg);
    }
    public static <T> ResultVO<T> error(T data) {
        if (data == null) {
//            log.warn("codeMsg is null");
            return null;
        }
        return new ResultVO<T>(data);
    }
}